<?php

namespace app\admin\controller;

use app\admin\model\VideoCategory;
use app\admin\model\VideoLevel;
use app\admin\model\VideoList;
use app\admin\service\VideoService;
use think\facade\Request;

class Video extends Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 列表
    public function index()
    {
        if (Request::isAjax()) {
            return $this->getJson(VideoList::getList());
        }
        $this->assign('levelList', VideoLevel::getLevelAll());
        $this->assign('categoryList', VideoCategory::getCategoryAll());
        return $this->fetch();
    }

    // 添加
    public function add()
    {
        if (Request::isAjax()) {
            return $this->getJson(VideoService::goAdd());
        }
        $this->assign('levelList', VideoLevel::getLevelAll());
        $this->assign('categoryList', VideoCategory::getCategoryAll());
        return $this->fetch();
    }

    // 编辑
    public function edit($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(VideoService::goEdit());
        }
        $data = VideoList::find($id);
        $this->assign('data', $data);
        $this->assign('levelList', VideoLevel::getLevelAll());
        $this->assign('categoryList', VideoCategory::getCategoryAll());
        return $this->fetch();
    }

    public function goRecommend()
    {
        return $this->getJson(VideoService::goRecommend());
    }

    public function goStatus()
    {
        return $this->getJson(VideoService::goStatus());
    }

    // 删除
    public function goRemove($id)
    {
        return $this->getJson(VideoService::goRemove($id));
    }

    // 列表
    public function level()
    {
        if (Request::isAjax()) {
            return $this->getJson(VideoLevel::getList());
        }
        return $this->fetch();
    }

    // 添加
    public function addLevel()
    {
        if (Request::isAjax()) {
            return $this->getJson(VideoService::goAddLevel());
        }
        return $this->fetch();
    }

    // 编辑
    public function editLevel($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(VideoService::goEditLevel());
        }
        $data = VideoLevel::find($id);
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function statusLevel()
    {
        return $this->getJson(VideoService::goStatusLevel());
    }

    // 删除
    public function removeLevel($id)
    {
        return $this->getJson(VideoService::goRemoveLevel($id));
    }

    // 列表
    public function category()
    {
        if (Request::isAjax()) {
            return $this->getJson(VideoCategory::getList());
        }
        return $this->fetch();
    }

    // 添加
    public function addCategory()
    {
        if (Request::isAjax()) {
            return $this->getJson(VideoService::goAddCategory());
        }
        return $this->fetch();
    }

    // 编辑
    public function editCategory($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(VideoService::goEditCategory());
        }
        $data = VideoCategory::find($id);
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function statusCategory()
    {
        return $this->getJson(VideoService::goStatusCategory());
    }

    // 删除
    public function removeCategory($id)
    {
        return $this->getJson(VideoService::goRemoveCategory($id));
    }
}